<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : member.class.php   FILE_PATH : \\classes\application\member.class.php
 * ....会员应用类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Nov 09 10:59:13 CST 2007
 */
defined('Base_Use_Sign') or die("this is invalid system!please contact .");
class MemberClass extends FrameWork {
	/**
	 * 构造检索条件
	 * @author workflow Develop Team
	 * @param  
	 * @return str
	 */
	function _conditionSearch($obj_condition){
		$conditionStr = "";

		if ($obj_condition[sys_group_id] != ""){/*权限组ID*/
			$conditionStr .= " and sys_group_id = '" . $obj_condition[sys_group_id] . "'";
		}
		if ($obj_condition['sys_login_name'] != ""){//权限会员名
			$conditionStr .= " and sys_login_name = '" . $obj_condition['sys_login_name'] . "'";
		}
		
		if ($obj_condition[order_group_id] == 1){/*权限组ID*/
			$conditionStr .=" order by sys_group_id";
		}
		if ($obj_condition[sys_member_id] != ""){
			$conditionStr .= " and sys_member_id = '" . $obj_condition[sys_member_id] . "'";
		}
		if ($obj_condition[order_log_id] == 1){/*日志ID*/
			$conditionStr .=" order by sys_log_id desc";
		}
		return $conditionStr;
	}
	
	/**
	 * 管理员列表
	 * @author workflow Develop Team
	 * @param  $obj_condition 搜索条件
	 * @return array
	 */
	function getSystemMemberList($obj_condition, &$obj_page){
		/**
		 * 构造查询条件
		 */
		$condition_str = $this->_conditionSearch($obj_condition);
		$sys_member_array = $GLOBALS['db']->GetList($condition_str, $obj_page, "system_member");
		return $sys_member_array;
	}

	/**
	 * 管理员列表
	 * @author workflow Develop Team
	 * @param  $obj_condition 搜索条件
	 * @return array
	 */
	function listMember($condition, &$obj_page){
		$sys_member_array = $GLOBALS['db']->GetJoinList($obj_page, array('system_member', 'department'), "left join", array("system_member.department_id=department.id"), array('*', 'name as dept_name'), $condition);
		return $sys_member_array;
	}
	
	/**
	 * 新增管理员
	 * @author workflow Develop Team
	 * @param  
	 * @return bool
	 */
	function addSysMember($input){

		$value_array = array();
		$value_array['sys_login_name'] = $input['sys_login_name'];
		$value_array['real_name']	= $input['real_name'];
		$value_array['sys_password']   = md5($input['sys_password']);
		$value_array['pic']    		   = $input['pic'];
		$value_array['sys_group_id']   = $input['sys_group_id'];
		$value_array['sys_login_time'] = time();
		$value_array['sys_email']      = $input['sys_email'];
		$value_array['gender']         = $input['gender'];
		$value_array['birthday']       = time($input['txtBirthday']);
		$value_array['department_id']  = $input['department'];
		if ($input['gongzi']) {
			$value_array['gongzi']            = $input['gongzi'];
		}
		if ($input['in_time']) {
			$value_array['in_time']           = strtotime($input['in_time']);
		}
		if ($input['out_time']) {
			$value_array['out_time']          = strtotime($input['out_time']);
		}
		$result = $GLOBALS['db']->InsertRow($value_array,'system_member','sys_member_id');
		if ($result !== true){
			return false;
		}
		return true;
	}

	/**
	 * 通过ID获得管理员信息
	 * @author workflow Develop Team
	 * @param  $sys_member_id 管理员ID
	 * @return array
	 */
	function getSysMemberById($sys_member_id){
		if (intval($sys_member_id) > 0){
			$array = $GLOBALS['db']->GetOneRow($sys_member_id,'system_member','sys_member_id');
		}
		return $array;
	}

	/**
	 * 更新管理员信息
	 * @author workflow Develop Team
	 * @param  $input 管理员信息
	 * @return bool
	 */
	function updateSysMember($input){

		$value_array = array();
		if ($input['sys_password'] != ""){
			$value_array['sys_password'] = md5($input['sys_password']);
		}

		$value_array['pic']    	   = $input['pic'];
		$value_array['real_name']  = $input['real_name'];
		$value_array['sys_group_id']   = $input['sys_group_id'];
		$value_array['sys_email']      = $input['sys_email'];
		$value_array['gender']         = $input['gender'];
		$value_array['birthday']       = time($input['txtBirthday']);
		$value_array['department_id']  = $input['department'];
		if ($input['gongzi']) {
			$value_array['gongzi']            = $input['gongzi'];
		}
		if ($input['in_time']) {
			$value_array['in_time']           = strtotime($input['in_time']);
		}
		if ($input['out_time']) {
			$value_array['out_time']          = strtotime($input['out_time']);
		}

		$update_rs = $GLOBALS['db']->UpdateRow($input['sys_member_id'],$value_array,'system_member','sys_member_id');
		if ($update_rs !== true) {
			return  false;
		}
		return true;
	}

	/**
	 * 删除管理员
	 * @author workflow Develop Team
	 * @param  $input 删除的管理员ID数组
	 * @return bool
	 */
	function delSysMember($input){
		if (trim($input) != ''){
			return $GLOBALS['db']->DelRow($input,'system_member','sys_member_id');
		}else {
			return false;
		}
	}
	/**
	 * 设置会员状态
	 *
	 * @param int $member_id 会员ID
	 * @param int $state 会员状态
	 * @return bool
	 */
	function _setMemberState($member_id,$state){
		$member_array = array();
		$member_array['status'] = $state;
		$update_rs = $GLOBALS['db']->UpdateRow($member_id,$member_array,"system_member","sys_member_id");
		return $update_rs;

	}
}
?>